package com.example.hw1;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    Button button;
    Button button2;
    EditText editText;
    TextView msg1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 布局文件
        setContentView(R.layout.activity_main);
        msg1 = findViewById(R.id.msg1);
        editText = findViewById(R.id.editTextText);
        button = findViewById(R.id.button);
        button2 = findViewById(R.id.button2);


        button.setOnClickListener(this);
        button2.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
//        if(id == R.id.button2){
//            editText.setText("hello "+editText.getText());
//        }else if(id == R.id.button){
//            msg1.setText("hello "+editText.getText());
//        }

        switch (id){
            case R.id.button:
                msg1.setText("hello "+editText.getText());
                break;
            case R.id.button2:
                editText.setText("hello "+editText.getText());
                break;
            default:
                msg1.setText("hello "+editText.getText());
        }


    }
}